package org.i_plus.model.services;

import org.hibernate.SessionFactory;
import org.i_plus.model.MapBean;
import org.i_plus.model.Map_ReplyBean;
import org.i_plus.model.dao.MapDAOHibernate;
import org.i_plus.model.dao.Map_ReplyDAOHibernate;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Map_ReplyService {
	private Map_ReplyDAOHibernate dao = null;
	private MapDAOHibernate mdao = null;

	public Map_ReplyService(Map_ReplyDAOHibernate dao) {
		this.dao = dao;
	}

	public void setMapDAO(MapDAOHibernate mdao) {
		this.mdao = mdao;
	}

	public void insert(int num, int num2, String acc, String cont,
			java.sql.Date time) {

		Map_ReplyBean bean = new Map_ReplyBean();

		bean.setM_re_num(num);
		MapBean temp = new MapBean();
		temp.setM_num(num2);
		bean.setMapBean(temp);// 原本是 setM_num
		bean.setM_re_acc(acc);
		bean.setM_re_content(cont);
		bean.setM_re_time(time);
		dao.insert(num, num2, acc, cont, time);

	}

	public void update(int num, int num2, String acc, String cont,
			java.sql.Date time) {

		Map_ReplyBean bean = new Map_ReplyBean();
		bean.setM_re_num(num);
		MapBean temp = new MapBean();
		temp.setM_num(num2);
		bean.setMapBean(temp);// 原本是 setM_num
		bean.setM_re_acc(acc);
		bean.setM_re_content(cont);
		bean.setM_re_time(time);
		dao.update(num, num2, acc, cont, time);

	}

	public void delete(int m_num) {
		dao.delete(m_num);
	}

	public void select() {
		dao.select();
	}

	public void selectByPK(int num) {
		dao.select_By_Num(num);
	}

	public static void main(String[] args) {
		// ApplicationContext
		// Map_ReplyService service
		// service.delete //提醒步驟用

		ApplicationContext context = new ClassPathXmlApplicationContext(
				"beans.config.xml");
		Map_ReplyService service = (Map_ReplyService) context
				.getBean("map_ReplyService");
		SessionFactory sessionFactory = (SessionFactory) context
				.getBean("sessionFactory");
		sessionFactory.getCurrentSession().beginTransaction();
		// 以下為測試程式

		// service.insert(11, 2, "BB", "BB",
		// java.sql.Date.valueOf("1985-6-25"));
		// System.out.println("done");

		// service.update(7, 2, "BB", "BB",
		// java.sql.Date.valueOf("1985-6-25"));
		// System.out.println("done");

		// service.delete(6);
		// System.out.println("done");

		// service.select();
		// System.out.println("done");

		// service.selectByPK(6);
		// System.out.println("done");

		// 以上為測試程式
		sessionFactory.getCurrentSession().getTransaction().commit();

	}

}
